package myky.com.doctorapp.adapter

import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import myky.com.doctorapp.R
import myky.com.doctorapp.entity.HealthItemEntity
import myky.com.doctorapp.wight.MyLayoutManager

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/14 on 17:25
 */
class HealthRecordAdapter(val healthList:List<HealthItemEntity>) : BaseMultiItemQuickAdapter<HealthItemEntity, BaseViewHolder>(healthList){


    init {

        addItemType(HealthItemEntity.DEFAULT, R.layout.health_record_item_default)
        addItemType(HealthItemEntity.HEADERLAYOUT, R.layout.health_record_item_header)
        addItemType(HealthItemEntity.FOOTLAYOUT, R.layout.health_record_item_foot)
    }

    override fun convert(helper: BaseViewHolder, item: HealthItemEntity) {
        when(item.type){
            HealthItemEntity.DEFAULT->{
            helper.setText(R.id.health_record_item_title,item.title)

            }
            HealthItemEntity.HEADERLAYOUT->{
            helper.setText(R.id.health_record_item_tvLeft,item.title)
            if(!TextUtils.isEmpty(item.content)) {
                helper.setText(R.id.health_record_item_tvRight, item.content)
            }

            }
            HealthItemEntity.FOOTLAYOUT->{
            helper.setText(R.id.activity_long_rang_health_item_tv1,item.title)
                var recyclerView = helper.getView<RecyclerView>(R.id.activity_long_rang_health_item_recycler)
                val myLayoutManager = MyLayoutManager()
                myLayoutManager.isAutoMeasureEnabled = true
                recyclerView.layoutManager = myLayoutManager
                var textsAdapter=TextsAdapter(item.stringList)
                recyclerView.adapter=textsAdapter
            }

        }
    }
}
